package com.geekaca.d09;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class HelloFile1 {
    public static void main(String[] args) {
        /**
         * File类的用法
         *
         */
        File file = new File("D:\\Users\\Peter\\Documents\\linux练习_杨煊友002.txt");
        System.out.println(file.length());
        boolean exists = file.exists();
        System.out.println("是否存在这个文件: " + exists);

        System.out.println("是普通文件" + file.isFile());
        System.out.println("是否文件夹 " + file.isDirectory());

        long lastModifyTime = file.lastModified();
        System.out.println("最后修改时戳为：" + lastModifyTime);
        // 时间戳转换为格式化字符串
        Date date1 = new Date(lastModifyTime);
        System.out.println("date1" + date1);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(date1));


        File myFile = new File("D:\\Users\\Peter\\Documents\\");
        System.out.println(myFile.isDirectory());

        File file2 = new File("C:/code/geekaca-data.log");
        System.out.println("file2 :" + file2.length());

        File f = new File(("c:" + File.separator + "code"));
        System.out.println(f);

        System.out.println(f.getAbsolutePath());

        System.out.println("================");
        File curFile = new File("./hello.txt");
        System.out.println("当前在哪个文件夹下" + curFile.getAbsolutePath());
        System.out.println("当前在哪个文件夹下" + curFile.getAbsoluteFile());

        File f3 = new File("Hello.txt");


        try {
            boolean isCreateOk = f3.createNewFile();
            System.out.println("是否创建成功: " + isCreateOk);
        } catch (IOException e) {
            e.printStackTrace();
        }
        f3.delete();
//        File myDir = new File("./testIO");
//        boolean isCreateDIR = myDir.mkdir();
//        System.out.println("创建目录: " + isCreateDIR);
//        myDir.delete();
//
//        File file4 = new File("/how.txt");
//        System.out.println(file4.getAbsolutePath());
//        System.out.println(file4.getPath());
//        try {
//            file4.createNewFile();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        file4.getName();

        //myDir 创建多级文件夹
//        File fdir = new File("./JavaSE/IO");
//        System.out.println(fdir.getAbsolutePath());
//        boolean isMkDirsOk = fdir.mkdirs();
//        System.out.println(isMkDirsOk);

    }
}
